package com.yf.words.util;

import com.alibaba.excel.EasyExcel;
import com.yf.words.excel.BaseListReadListener;
import lombok.extern.log4j.Log4j2;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

@Log4j2
public class DataUtil {

    public static <T> List<T> getListData(Class<T> tClass, String fileName, String sheetName) {

        BaseListReadListener<T> listener = new BaseListReadListener<>();
        try {
            File file = ResourceUtils.getFile(fileName);
            EasyExcel.read(file, tClass, listener).sheet(sheetName).doRead();
        } catch (FileNotFoundException e) {
            log.error(fileName + " not found");
        }
        return listener.getList();
    }
}